package com.atguigu.test.rabbitmq.controller;

import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@RestController
public class SendMq {
    @Autowired
    RabbitTemplate rabbitTemplate;
    @GetMapping("/send")
    public String sendMQ(){
        for (int i = 0; i < 4; i++) {

            User user = new User();
            user.setUsername("aaa"+i);
            rabbitTemplate.convertAndSend("two-java-exchange","two.java",user,new CorrelationData(UUID.randomUUID().toString()));
        }
        return "send=ok";
    }

    @GetMapping("/send2")
    public String sendMQ2(){
        User user = new User();
        user.setUsername("aaa");


        rabbitTemplate.convertAndSend("two-java-exchange","two1.java",user,new CorrelationData(UUID.randomUUID().toString()));
        return "send=ok";
    }
}
